package com.my.meitianbackup.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;
import com.my.meitianbackup.controller.DetailController;
import com.my.meitianbackup.controller.IndexController;
import com.my.meitianbackup.model._MappingKit;

public class MainConfig extends JFinalConfig {

	public void configConstant(Constants me) {
		PropKit.use("config.properties");
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
		me.setEncoding("utf-8");
	}

	public void configRoute(Routes me) {
		me.add("/", IndexController.class);
		me.add("/detail", DetailController.class, "pages/");
	}

	public void configEngine(Engine me) {
	}

	public static C3p0Plugin createC3p0Plugin() {
		return new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
	}

	public void configPlugin(Plugins me) {
		C3p0Plugin C3p0Plugin = createC3p0Plugin();
		me.add(C3p0Plugin);

		ActiveRecordPlugin arp = new ActiveRecordPlugin(C3p0Plugin);
		me.add(arp);
		_MappingKit.mapping(arp);
	}

	public void configInterceptor(Interceptors me) {
	}

	public void configHandler(Handlers me) {
	}

	public static void main(String[] args) {
		JFinal.start("webapp", 8080, "/", 5);
	}
}
